﻿@model wychuan2.com.Areas.admin.Models.LiCai.BillModel
@using AC.Util
@using AC.Service.DTO.LiCai;
@{
    ViewBag.Title = "理财-记账";
    Layout = "../Shared/_Layout.cshtml";
}

@{
    List<ItemDTO> lstBooks = Model.Items.Where(m => m.Type == ItemType.BillBook).ToList();
    List<ItemDTO> lstProjects = Model.Items.Where(m => m.Type == ItemType.Project).ToList();
    List<ItemDTO> lstMembers = Model.Items.Where(m => m.Type == ItemType.Member).ToList();
    List<ItemDTO> lstBusiness = Model.Items.Where(m => m.Type == ItemType.Business).ToList();
    string strCategories = JsonHelper.ToJson(Model.Categories);
}

@section styles{
    <link href="~/Content/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="~/Content/plugins/datetimepicker/jquery.datetimepicker.css" rel="stylesheet" />
    @*<link href="~/Content/plugins/chosen/chosen.css" rel="stylesheet" />*@
}
<div class="row">
    <div class="col-lg-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="alert alert-warning alert-dismissable">
                            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                            <a href="/admin/licai/fastbill" class="btn btn-white">快速记账</a>
                            <a href="/admin/licai/details" class="btn btn-white">查看明细</a>
                        </div>
                    </div>
                </div>
                <ul class="nav nav-tabs" role="tablist">
                    <li class="active" role="presentation"><a href="#tab1" role="tab" data-toggle="tab">支出</a></li>
                    <li role="presentation"><a href="#tab2" role="tab" data-toggle="tab">收入</a></li>
                    <li role="presentation"><a href="#tab3" role="tab" data-toggle="tab">转账</a></li>
                    <li role="presentation"><a href="#tab4" role="tab" data-toggle="tab">借贷</a></li>
                </ul>

                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane active" id="tab1">
                        <div class="panel">
                            <div class="panel-body">
                                <form class="form-horizontal" role="form" id="frmExpend" novalidate="novalidate">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账本</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBook">
                                                @foreach (var book in lstBooks)
                                                {
                                                    <option value="@book.Id">@book.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">金额</label>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon">￥</span>
                                                <input name="txtPrice" type="text" value="0.0" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">类别</label>
                                        @{
                                            var lstFirsts = Model.Categories.Where(c => c.InOutType == CategoryType.Expend && c.ParentId == 0).OrderByDescending(c => c.IsCommonUse);
                                            var lstSeconds = Model.Categories.Where(c => c.ParentId == lstFirsts.FirstOrDefault().Id).OrderByDescending(c => c.IsCommonUse);
                                        }
                                        <div class="col-sm-5">
                                            <div class="input-group">
                                                <select class="input-sm form-control" name="selFirstCategory">
                                                    @foreach (var first in lstFirsts)
                                                    {
                                                        <option value="@first.Id">@first.Name</option>
                                                    }
                                                </select>
                                                <span class="input-group-addon">-</span>
                                                <select class="input-sm form-control" name="selCategory">
                                                    @foreach (var first in lstSeconds)
                                                    {
                                                        <option value="@first.Id">@first.Name</option>
                                                    }
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">商家</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBusiness">
                                                <option value="0">商家</option>
                                                @foreach (var business in lstBusiness)
                                                {
                                                    <option value="@business.Id">@business.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账户</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selAccount">
                                                @foreach (var account in Model.Accounts)
                                                {
                                                    <option value="@account.Id">@(account.Name + "(" + account.Currency + ")")</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">时间</label>
                                        <div class="col-sm-3">
                                            <input name="txtConsumeTime" type="text" class="form-control datetimepicker" value="@DateTime.Now.ToString("yyyy/MM/dd HH:mm")" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">项目</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selProject">
                                                @foreach (var project in lstProjects)
                                                {
                                                    <option value="@project.Id">@project.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">成员</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selMember">
                                                @foreach (var member in lstMembers)
                                                {
                                                    <option value="@member.Id">@member.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>

                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">备注</label>
                                        <div class="col-sm-5">
                                            <textarea name="txtRemark" cols="10" rows="3" class="form-control" placeholder="输入备注信息"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-1 col-sm-11">
                                            <label class="checkbox-inline i-checks">
                                                <input name="chkBaoXiao" type="checkbox" class="form-control">  可报销
                                            </label>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-1">
                                            <button name="btnSave" class="btn btn-primary" data-clear="false" data-type="@BillDetailType.Expend.GetHashCode()" type="button"><strong>保存</strong></button>
                                            <button name="btnSaveContinue" class="btn btn-danger" data-clear="true" data-type="@BillDetailType.Expend.GetHashCode()" type="button"><strong>保存后再记</strong></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="tab2">
                        <div class="panel">
                            <div class="panel-body">
                                <form class="form-horizontal" role="form" id="frmIncome" novalidate="novalidate">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账本</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBook">
                                                @foreach (var item in lstBooks)
                                                {
                                                    <option value="@item.Id">@item.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">金额</label>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon">￥</span>
                                                <input name="txtPrice" type="text" value="0.00" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">类别</label>

                                        <div class="col-sm-5">
                                            <div class="input-group">
                                                @{
                                                    List<CategoryDTO> lstIncomeFirstLevels = Model.Categories.Where(c => c.InOutType == CategoryType.Income && c.ParentId == 0).OrderByDescending(c => c.IsCommonUse).ToList();
                                                    List<CategoryDTO> lstChilds = Model.Categories.Where(c => c.ParentId == lstIncomeFirstLevels.FirstOrDefault().Id).OrderByDescending(c => c.IsCommonUse).ToList();
                                                }
                                                <select class="input-sm form-control" name="selFirstCategory">
                                                    @foreach (var first in lstIncomeFirstLevels)
                                                    {
                                                        <option value="@first.Id">@first.Name</option>
                                                    }
                                                </select>
                                                <span class="input-group-addon">-</span>
                                                <select class="input-sm form-control" name="selCategory">
                                                    @foreach (var child in lstChilds)
                                                    {
                                                        <option value="@child.Id">@child.Name</option>
                                                    }
                                                </select>
                                            </div>

                                            @*<select class="form-control" name="selCategory">
                                                @{
                                                    List<CategoryDTO> lstIncomeFirstLevels = Model.Categories.Where(c => c.InOutType == CategoryType.Income && c.ParentId == 0).OrderByDescending(c => c.IsCommonUse).ToList();
                                                    foreach (var category in lstIncomeFirstLevels)
                                                    {
                                                        List<CategoryDTO> lstChilds = Model.Categories.Where(c => c.ParentId == category.Id).ToList();
                                                        if (lstChilds.Count > 0)
                                                        {
                                                            foreach (var child in lstChilds)
                                                            {
                                                                <option value="@child.Id">@(category.Name + " - " + child.Name)</option>
                                                            }
                                                        }
                                                    }
                                                }
                                            </select>*@
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">付款方</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBusiness">
                                                @foreach (var pay in Model.Items.Where(m => m.Type == ItemType.PaymentPerson))
                                                {
                                                    <option value="@pay.Id">@pay.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账户</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selAccount">
                                                @foreach (var item in Model.Accounts)
                                                {
                                                    <option value="@item.Id">@item.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">时间</label>
                                        <div class="col-sm-3">
                                            <input name="txtConsumeTime" type="text" class="form-control datetimepicker" value="@DateTime.Now.ToString("yyyy/MM/dd HH:mm")" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">项目</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selProject">
                                                @foreach (var project in lstProjects)
                                                {
                                                    <option value="@project.Id">@project.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">成员</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selMember">
                                                @foreach (var member in lstMembers)
                                                {
                                                    <option value="@member.Id">@member.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">备注</label>
                                        <div class="col-sm-5">
                                            <textarea name="txtRemark" cols="10" rows="3" class="form-control"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-1">
                                            <button name="btnSave" class="btn btn-primary" data-clear="false" data-type="@BillDetailType.Income.GetHashCode()" type="button"><strong>保存</strong></button>
                                            <button name="btnSaveContinue" class="btn btn-danger" data-clear="true" data-type="@BillDetailType.Income.GetHashCode()" type="button"><strong>保存后再记</strong></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="tab3">
                        <div class="panel">
                            <div class="panel-body">
                                <form class="form-horizontal" role="form" id="form1" novalidate="novalidate">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账本</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBook">
                                                @foreach (var item in lstBooks)
                                                {
                                                    <option value="@item.Id">@item.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">账户</label>
                                        <div class="col-sm-4">
                                            <div class="input-group">
                                                <select class="input-sm form-control" name="selAccount">
                                                    @foreach (var item in Model.Accounts)
                                                    {
                                                        <option value="@item.Id">@item.Name</option>
                                                    }
                                                </select>
                                                <span class="input-group-addon">-></span>
                                                <select class="input-sm form-control" name="selAccountTo">
                                                    @foreach (var item in Model.Accounts)
                                                    {
                                                        <option value="@item.Id">@item.Name</option>
                                                    }
                                                </select>
                                            </div>

                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">金额</label>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon">￥</span>
                                                <input name="txtPrice" type="text" value="0.00" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">时间</label>
                                        <div class="col-sm-3">
                                            <input name="txtConsumeTime" value="@DateTime.Now.ToString("yyyy/MM/dd HH:mm")" type="text" class="form-control datetimepicker" />
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">备注</label>
                                        <div class="col-sm-5">
                                            <textarea name="txtRemark" cols="10" rows="3" class="form-control"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-1">
                                            <button name="btnSave" class="btn btn-primary" data-clear="false" data-type="@BillDetailType.Transfer.GetHashCode()" type="button"><strong>保存</strong></button>
                                            <button name="btnSaveContinue" class="btn btn-danger" data-clear="true" data-type="@BillDetailType.Transfer.GetHashCode()" type="button"><strong>保存后再记</strong></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="tab4">
                        <div class="panel">
                            <div class="panel-body">
                                <form class="form-horizontal" role="form" id="form4" novalidate="novalidate">
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label" for="selBook">账本</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBook">
                                                @foreach (var item in lstBooks)
                                                {
                                                    <option value="@item.Id">@item.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label" for="selCreditorType">类别</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selCreditorType">
                                                <option value="1">借入</option>
                                                <option value="2">借出</option>
                                                <option value="3">收款</option>
                                                <option value="4">还款</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">金额</label>
                                        <div class="col-sm-3">
                                            <div class="input-group">
                                                <span class="input-group-addon">￥</span>
                                                <input name="txtPrice" type="text" value="0.0" class="form-control" />
                                            </div>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">债权人</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selBusiness">
                                                @foreach (var item in Model.Items.Where(m => m.Type == ItemType.Creditor))
                                                {
                                                    <option value="@item.Id">@item.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">借入账户</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selAccount">
                                                @foreach (var account in Model.Accounts)
                                                {
                                                    <option value="@account.Id">@account.Name</option>
                                                }
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">时间</label>
                                        <div class="col-sm-3">
                                            <input name="txtConsumeTime" value="@DateTime.Now.ToString("yyyy/MM/dd HH:mm")" type="text" class="form-control datetimepicker" />
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">还款日</label>
                                        <div class="col-sm-3">
                                            <input name="txtRefundTime" type="text" class="form-control datetimepicker" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">还款提醒</label>
                                        <div class="col-sm-3">
                                            <select class="form-control" name="selRefundNotice">
                                                <option>无需提醒</option>
                                                <option>提醒一次</option>
                                                <option>每月提醒</option>
                                            </select>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">备注</label>
                                        <div class="col-sm-5">
                                            <textarea name="txtRemark" cols="10" rows="3" class="form-control"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-1">
                                            <button name="btnSave" data-clear="false" data-type="@BillDetailType.Creditor.GetHashCode()" class="btn btn-primary" type="button"><strong>保存</strong></button>
                                            <button name="btnSaveContinue" data-clear="true" data-type="@BillDetailType.Creditor.GetHashCode()" class="btn btn-danger" type="button"><strong>保存后再记</strong></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

@section scripts{
    <script src="~/Scripts/plugins/iCheck/icheck.min.js"></script>
    <script src="~/Scripts/plugins/validate/jquery.validate.min.js"></script>
    <script src="~/Scripts/plugins/validate/messages_zh.js"></script>
    <script src="~/Scripts/plugins/datetimepicker/jquery.datetimepicker.js"></script>
    @*<script src="~/Scripts/plugins/chosen/chosen.jquery.js"></script>*@
    <script>
        window.categories=@Html.Raw(strCategories);
    </script>
    <script src="~/Scripts/licai/bill.js"></script>
}